package com.pay.cloud.fragment;

import com.pay.cloud.R;
import com.pay.cloud.cpay.MyCloudPay;
import com.tencent.cloudpay.param.CloseOrderRequest;
import com.tencent.cloudpay.param.QueryOrderRequest;
import com.tencent.cloudpay.param.QueryOrderResponse;
import com.tencent.cloudpay.pojo.TradeType;

public class PayCancelFragment extends PayCancelAbstract {
    private String orderNo;

    public PayCancelFragment(String orderNo, String amount) {
        super(orderNo, amount);
        this.orderNo = orderNo;
    }

    @Override
    public void execute() throws Exception {
        super.execute();

        QueryOrderRequest oReq = new QueryOrderRequest();
        oReq.setOut_trade_no(orderNo);
        QueryOrderResponse oRes = MyCloudPay.getInstance(getActivity()).queryOrder(oReq);

        CloseOrderRequest req = new CloseOrderRequest();
        req.setOut_trade_no(orderNo);
        req.setTrade_type(TradeType.MicroPay);
        req.setPay_platform(oRes.getOrder().getPay_platform());
        boolean success = MyCloudPay.getInstance(getActivity()).closeOrder(req);

        if (success) {
            onSuccess();
        } else {
            onFail(getString(R.string.cancel_fail));
        }
    }

}
